<?php

class Application_Model_Supplier extends Zend_Db_Table_Abstract
{
    protected $_name = 'tabel_supplier';
    
    public function supplierBaru($data)
    {
        $this->insert($data);
    }
    
    public function getSupplier($id) {
        $id = (int)$id;
        $row = $this->fetchRow('id_supplier = '.$id);
        if(!$row)
            return false;
        else
            return $row->toArray ();
    }
    
    public function supplierUpdate($data, $id)
    {
        $this->update($data, 'id_supplier = '.(int)$id);   
    }
    
    public function supplierDelete($id){
        $this->delete('id_supplier = '.(int)$id);
    }


    public function checkSupplier($nama) {
        $select = $this->select();
        $select->where("nama_supplier= ?",$nama);
        $row = $this->fetchAll($select)->count();
        if($row > 0)
            return true;
        else
            return false;
    }
    
    public function  getAllData()
    {
        $data = $this->fetchAll()->toArray();
        return $data;
    }
    
    public function checkRowSupplier()
    {
        $row = $this->fetchAll()->count();
        return $row;
    }
    
    public function getDataJoin()
    {
        $select = $this->select();
        $select->setIntegrityCheck(false);
        $select->from($this->_name);
        
        $select->joinLeft('tabel_status_supplier', 'tabel_supplier.id_status_supplier = tabel_status_supplier.id_status_supplier',
                            array('status_supplier' => 'status_supplier'));
    
        $result = $this->fetchAll($select)->toArray();
        return $result;
    }
    
    public function getDataJoinWithId($id)
    {
        $select = $this->select();
        $select->setIntegrityCheck(false);
        $select->from($this->_name)
               ->where('id_supplier = ?', $id);
        
        $select->joinLeft('tabel_status_supplier', 'tabel_supplier.id_status_supplier = tabel_status_supplier.id_status_supplier',
                            array('status_supplier' => 'status_supplier'));
    
        $result = $this->fetchAll($select)->toArray();
        return $result;
    }

}

